<template>

  <el-dialog
    :close-on-click-modal="false"
    :visible.sync="visible"
    @open="refreshDataForm"
    @close="refreshDataForm"
  >
    <h1 style="color: deepskyblue">个人信息修改</h1>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="民族" prop="schoolSystem">
      <el-input v-model="dataForm.nation" placeholder="民族"></el-input>
    </el-form-item>
    <el-form-item label="籍贯" prop="schoolYear">
      <el-input v-model="dataForm.nativePlace" placeholder="籍贯"></el-input>
    </el-form-item>
    <el-form-item label="政治面貌" prop="trainFee">
      <el-input v-model="dataForm.politicalStatus" placeholder="政治面貌"></el-input>
    </el-form-item>
    <el-form-item label="紧急联系人" prop="clothesFee">
      <el-input v-model="dataForm.familyMemberName" placeholder="紧急联系人"></el-input>
    </el-form-item>
      <el-form-item label="联系人手机号" prop="clothesFee">
        <el-input v-model="dataForm.familyPhone" placeholder="联系人手机号"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="clothesFee">
        <el-input v-model="dataForm.phone" placeholder="手机号"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="clothesFee">
        <el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
      </el-form-item>
      <el-form-item label="居住地" prop="clothesFee">
        <el-input v-model="dataForm.familyAddr" placeholder="居住地"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import axios from "axios";

  export default {
    props:{
    phoneFa: {
      type: String,	  // name传入类型必须为字符串
      required: true    // name设为必传字段
    },
    },
    name: "studentInfoupdate",
    data () {
      return {
        visible: false,
        dataForm: {
          stuId:'',
          nation: '',
          nativePlace: '',
          politicalStatus: '',
          familyMemberName: '',
          familyPhone: '',
          phone: '',
          familyAddr: '',
          email:''
        },
        dataRule: {
          nation: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          nativePlace: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          politicalStatus: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          familyMemberName: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          familyPhone: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          familyAddr: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          email: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
        },
        }
      },

    created() {
      this.refreshDataForm()
    },
    methods: {

      dataFormSubmit(){
        axios.post('/api/app/update/',this.dataForm).then((res)=> {
          console.log(res);
          this.$message(res.data.msg)
        })
      },
      refreshDataForm (){
        axios.get('/api/app/info/'+localStorage.getItem("studentId")).then((res)=>{
          console.log(res)
          this.dataForm.nation = res.data.nation
          this.dataForm.nativePlace = res.data.nativePlace
          this.dataForm.phone = res.data.phone
          this.dataForm.politicalStatus = res.data.politicalStatus
          this.dataForm.familyAddr = res.data.familyAddr
          this.dataForm.familyPhone = res.data.familyPhone
          this.dataForm.familyMemberName = res.data.familyMemberName
          this.dataForm.stuId = res.data.stuId
          this.dataForm.email = res.data.email
        })
        //this.dataForm.phone=this.phoneFa
      },

      init () {
        this.visible = true
        console.log(555);
      },
    }
  }
</script>
